import java.util.PriorityQueue;

public class demo2 {
    public ListNode mergeKLists(ListNode[] lists) {
        PriorityQueue<ListNode>priorityQueue=new PriorityQueue<ListNode>((v1,v2)-> v1.val- v2.val);
      for(ListNode temp:lists){
          priorityQueue.offer(temp);
      }
      ListNode newhead=new ListNode();
      ListNode cur=newhead;
      while(priorityQueue.size()!=0){
          ListNode ret=priorityQueue.poll();
          cur.next=ret;
          cur=ret;
          if (ret.next!=null) priorityQueue.offer(ret.next);
      }
      return newhead;
    }
}
